package com.example.android_test_homekey;

import com.example.android_test_homekey.HomeWatcher.OnHomePressedListener;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity implements OnHomePressedListener {
	public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000;
	private HomeWatcher mHomeWatcher = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED,
				FLAG_HOMEKEY_DISPATCHED);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	protected void onResume() {
		mHomeWatcher = new HomeWatcher(this);
		mHomeWatcher.setOnHomePressedListener(this);
		mHomeWatcher.startWatch();
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		mHomeWatcher.setOnHomePressedListener(null);
		mHomeWatcher.stopWatch();
	}

	@Override
	public void onHomePressed() {
		Log.e("onHomePressed", "onHomePressed");

	}

	@Override
	public void onHomeLongPressed() {
		Log.e("onHomeLongPressed", "onHomeLongPressed");
	}
}
